<template>
  <div class="content content53">
    <div>检测条件：温度T：<el-input v-model="form.temperature" class="input-line" />℃；气压p：<el-input v-model="form.pressure" class="input-line" />Kpa</div>
    <div class="innertitle">
      1.源活度：<span style="font-weight: normal;">
        <el-select v-model="form.sourceActivity.systemType" placeholder="请选择">
            <el-option
              v-for="item in [{'value':0,'label':'电离室与施源器不匹配'},{'value':1,'label':'步进多源系统'},{'value':2,'label':'固定多源系统'}]"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
      </span>
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>放射源类型</td>
        <td>设置时间</td>
        <td>显示源活度<i>$A_{app,B}$</i>，Bq</td>
        <td>静电计刻度系数<i>$N_E$</i></td>
        <td>刻度因子<i>$N_{SK}$</i></td>
      </tr>
      <tr>
        <td style="min-width: 140px;">
          <el-radio-group v-model="form.sourceActivity.radioactiveSource">
              <el-radio :label="0"><i>$^{192}Ir$</i>源</el-radio>
              <el-radio :label="1"><i>$^{137}Cs$</i>源</el-radio>
              <el-radio :label="2"><i>$^{60}Co$</i>源</el-radio>
          </el-radio-group>
        </td>
        <td class="multipleInput"><el-input v-model="form.sourceActivity.second" class="input-line" />s</td>
        <td><el-input v-model="form.sourceActivity.sourceActivity" class="input-line" /></td>
        <td><el-input v-model="form.sourceActivity.coefficient" class="input-line" /></td>
        <td><el-input v-model="form.sourceActivity.scaleFactor" class="input-line" /></td>
      </tr>
    </table>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>测量条件</td>
        <td :colspan="sourceActivity.table.td">极性电压400V</td>
        <td rowspan="2">极性电压<br/>200V</td>
        <td rowspan="2">电离电荷复合率<br/>校准因子<i>$A_{ion}$</i></td>
        <td rowspan="2">实测源活度<br/><i>$A_{app,t}$</i>,Bq</td>
        <td rowspan="2">活度偏差<br/>DeV%</td>
      </tr>
      <tr>
        <td>测量次数</td>
        <td v-for="tdIndex in sourceActivity.table.td" :key="tdIndex">{{tdIndex}}</td>
      </tr>
      <tr>
        <td>读数<i>$M_u$</i>(nA）</td>
        <td v-for="tdIndex in sourceActivity.table.td" :key="tdIndex">
          <el-input v-model="form.sourceActivity['readoutValue_'+tdIndex]" class="input-line"  />
        </td>
        <td><el-input v-model="form.sourceActivity.polarityVoltage" class="input-line" /></td>
        <td><el-input v-model="form.sourceActivity.compositeCalibrationFactor" class="input-line" /></td>
        <td style="word-wrap: break-word;">{{form.sourceActivity.measuredSourceActivity}}</td>
        <td><el-input v-model="form.sourceActivity.activityDeviation" class="input-line" /></td>
      </tr>
    </table>
    <div style="margin-top: 15px;">
      <i>$A_{ion} = \frac {4}{3} - \frac {1}{3} \times \frac {Q_1}{Q_2}$</i>
      ，&nbsp;&nbsp;<i>$s_K = M_u \times N_{SK} \times N_E \times C_{T \cdot p} \times A_{ion}$</i>
      ，&nbsp;&nbsp;<i>$DeV = \frac {A_{app,B} - A_{app,t}}{A_{app,t}} \times 100\%$</i>
    </div>
    <div class="innertitle">
      2.源到位精度：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>测量位置</td>
        <td>预设值，mm</td>
        <td>实测值，mm</td>
        <td>差值，mm</td>
      </tr>
      <tr v-for="trIndex in sourcePlaceAccuracy.table.tr" :key="trIndex">
        <td :rowspan="sourcePlaceAccuracy.table.tr" v-if="trIndex == 1" class="multipleInput">
          第<el-input v-model="form.sourcePlaceAccuracy.number" class="input-line" />通道
        </td>
        <td><el-input v-model="form.sourcePlaceAccuracy['presets_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.sourcePlaceAccuracy['measuredValue_'+trIndex]" class="input-line" /></td>
        <td><el-input v-model="form.sourcePlaceAccuracy['difference_'+trIndex]" class="input-line" /></td>
      </tr>
    </table>
    <div>
      差值 = 预设值 - 测量值
    </div>
    <div class="innertitle">
      3.放射源累计定位误差
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>驻留点d</td>
        <td v-for="tdIndex in accumulatedPositioningError.table.td" :key="tdIndex">{{tdIndex}}</td>
      </tr>
      <tr>
        <td>预设值，mm</td>
        <td v-for="tdIndex in accumulatedPositioningError.table.td" :key="tdIndex"><el-input v-model="form.accumulatedPositioningError['presets_'+tdIndex]" class="input-line" /></td>
      </tr>
      <tr>
        <td>实测值，mm</td>
        <td v-for="tdIndex in accumulatedPositioningError.table.td" :key="tdIndex"><el-input v-model="form.accumulatedPositioningError['measuredValue_'+tdIndex]" class="input-line" /></td>
      </tr>
      <tr>
        <td>偏差d，mm</td>
        <td v-for="tdIndex in accumulatedPositioningError.table.td" :key="tdIndex"><el-input v-model="form.accumulatedPositioningError['deviation_'+tdIndex]" class="input-line" /></td>
      </tr>
      <tr>
        <td>计算结果S，mm</td>
        <td :colspan="accumulatedPositioningError.table.td"><el-input v-model="form.accumulatedPositioningError.result" class="input-line" /></td>
      </tr>
    </table>
    <div>
      <i>$S=d_1 + d_2 + d_3 + \ldots + d_{10}$</i>
    </div>
    <div class="innertitle">
      4.源驻留时间误差：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td>设置时间</td>
        <td>测量次数</td>
        <td v-for="tdIndex in dwellTimeError.table.td" :key="tdIndex">{{tdIndex}}</td>
        <td>平均值</td>
        <td>差值</td>
      </tr>
      <tr>
        <td>60s</td>
        <td>检测结果，s</td>
        <td v-for="tdIndex in dwellTimeError.table.td" :key="tdIndex"><el-input v-model="form.dwellTimeError['result_'+tdIndex]" class="input-line" /></td>
        <td><el-input v-model="form.dwellTimeError.averageValue" class="input-line" /></td>
        <td><el-input v-model="form.dwellTimeError.difference" class="input-line" /></td>
      </tr>
    </table>
    <div>
      差值 = 预设值 - 测量值
    </div>
    <div class="innertitle">
      5.多源系统重复性：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td colspan="2">设置时间：60s</td>
        <td :colspan="repeatability.table.td + 1">仪器读数<i>$X_i$</i></td>
        <td rowspan="2">计算结果%</td>
      </tr>
      <tr>
        <td colspan="2">测量次数n</td>
        <td v-for="tdIndex in repeatability.table.td" :key="tdIndex">{{tdIndex}}</td>
        <td>平均值<br/><i>$\overline X$</i></td>
      </tr>
      <tr v-for="trIndex in repeatability.table.tr" :key="trIndex">
        <td :rowspan="repeatability.table.tr -1" v-if="trIndex == 2">随机通道</td>
        <td :colspan="trIndex == 1 ? 2:1" class="multipleInput" style="min-width: 120px;">第<el-input v-model="form.repeatability['number_'+trIndex]" class="input-line" />通道</td>
        <td v-for="tdIndex in repeatability.table.td" :key="tdIndex"><el-input v-model="form.repeatability['readoutValue_'+trIndex+'_'+tdIndex]" class="input-line" /></td>
        <td v-if="trIndex == 1"><el-input v-model="form.repeatability.averageValue_1" class="input-line" /></td>
        <td :rowspan="repeatability.table.tr -1" v-if="trIndex == 2"><el-input v-model="form.repeatability.averageValue_2" class="input-line" /></td>
        <td v-if="trIndex == 1"><el-input v-model="form.repeatability.result_1" class="input-line" /></td>
        <td :rowspan="repeatability.table.tr -1" v-if="trIndex == 2"><el-input v-model="form.repeatability.result_2" class="input-line" /></td>
      </tr>
    </table>
    <div class="latex">
      <i>$\overline {X} = \frac {1}{n} \sum\limits_{i=1}^{n} X_i$</i>
      ，&nbsp;&nbsp;<i>$V= \frac {1}{\overline X} \sqrt{\sum (X_i - \overline X)^2 / (n-1)} \times 100 \%$</i>
    </div>
    <div class="innertitle">
      6.贮源器表面泄漏辐射所致周围剂量当量率：
    </div>
    <table border="1" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td colspan="2">放射源种类</td>
        <td>源活度,Bq</td>
        <td :colspan="doseEquivalentRate.table.td">本底测量值,nGy/h</td>
        <td>校准因子f</td>
      </tr>
      <tr>
        <td  colspan="2">
          <el-radio-group v-model="form.doseEquivalentRate.radioactiveSource">
              <el-radio :label="0"><i>$^{192}Ir$</i>源</el-radio>
              <el-radio :label="1"><i>$^{137}Cs$</i>源</el-radio>
              <el-radio :label="2"><i>$^{60}Co$</i>源</el-radio>
          </el-radio-group>
        </td>
        <td><el-input v-model="form.doseEquivalentRate.sourceActivity" class="input-line" /></td>
        <td v-for="tdIndex in doseEquivalentRate.table.td" :key="tdIndex"><el-input v-model="form.doseEquivalentRate['measurementValue_'+tdIndex]" class="input-line" /></td>
        <td><el-input v-model="form.doseEquivalentRate.calibrationFactor" class="input-line" /></td>
      </tr>
      <tr>
        <td>修正值K<br/>μGy/h</td>
        <td style="min-width: 240px;">5cm处泄漏辐射所致周围剂量当量率</td>
        <td colspan="2"><el-input v-model="form.doseEquivalentRate.correctedValue_1" class="input-line" /></td>
        <td :colspan="doseEquivalentRate.table.td-2">100cm处泄漏辐射所致周围剂量当量率</td>
        <td colspan="2"><el-input v-model="form.doseEquivalentRate.correctedValue_2" class="input-line" /></td>
      </tr>
      <tr>
        <td :colspan="doseEquivalentRate.table.td + 4">附注：1、下图中阴影区域内各位点测量值<i>$K_1$</i>；2、检测结果取各位点剂量率最大值且未扣除本底值</td>
      </tr>
    </table>
    <div class="latex">
      <i>$K=K_1 \cdot f$</i>
    </div>
    <div style="display: flex;justify-content: center; position: relative;">
      <img src="@/assets/images/test_item53/form_6_1.png" alt="" style="margin-right: 50px;">
      <!-- 左边外圈 -->
      <el-input style="position: absolute; top: 0px; left: 310px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 45px; left: 195px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 135px; left: 155px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 248px; left: 185px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 308px; left: 335px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 250px; left: 458px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 152px; left: 495px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 45px; left: 449px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <!-- 左边内圈 -->
      <el-input style="position: absolute; top: 92px; left: 320px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 110px; left: 263px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 153px; left: 245px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 198px; left: 260px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 243px; left: 268px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 254px; left: 324px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 243px; left: 378px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 194px; left: 386px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 154px; left: 400px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 111px; left: 383px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <!-- 右边外圈 -->
      <el-input style="position: absolute; top: 13px; right: 386px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 51px; right: 505px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 152px; right: 549px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 260px; right: 518px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 263px; right: 244px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 153px; right: 203px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 52px; right: 254px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <!-- 右边内圈 -->
      <el-input style="position: absolute; top: 112px; right: 368px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 112px; right: 417px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 158px; right: 437px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 195px; right: 448px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 159px; right: 263px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 124px; right: 272px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
      <el-input style="position: absolute; top: 112px; right: 320px; width: 50px; height: 30px;"
      v-model="form.doseEquivalentRate.comment"/>
    </div>
  </div>
</template>

<script>
  import {getInfoById, postInfo} from '@/api/testItem/item53'
import { watch } from 'vue'
  export default{
    name:'testItem53',
    props: {
    	// tab栏
      activeNameEquipment: {
    		type: String,
        default: "0",
      },
    	// 基本信息数据
      basicForm: {
    		type: Object,
        default: () => {
    			return {}
    		},
      },
    },
    data(){
      return {
        "sdd": {
          action:'saveInfo',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
        },
        "sourceActivity": {
          action:'sourceActivity',
          flag:true,
          loading:false,
          notNumber:['systemType','radioactiveSource'],
          intNumber:['second'],
          like:false,
          table:{
            td:5
          }
        },
        "sourcePlaceAccuracy": {
          action:'accuracy',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:['number'],
          like:false,
          table:{
            tr:3
          }
        },
        "accumulatedPositioningError": {
          action:'positioningError',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            td:10
          }
        },
        "dwellTimeError": {
          action:'dwellTimeError',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:[],
          like:false,
          table:{
            td:3
          }
        },
        "repeatability": {
          action:'repeatability',
          flag:true,
          loading:false,
          notNumber:[],
          intNumber:['number'],
          like:true,
          table:{
            td:10,
            tr:4
          }
        },
        "doseEquivalentRate": {
          action:'doseEquivalentRate',
          flag:true,
          loading:false,
          notNumber:['radioactiveSource'],
          intNumber:[],
          like:false,
          table:{
            td:5
          }
        },
        initFlag:false,
        "form": {
          "itemsId": 0,
          "resultId": 0,
          "temperature": 0.0,
          "pressure": 0.0,
          "sourceActivity": {
            "itemsId": 0
          },
          "sourcePlaceAccuracy": {
            "itemsId": 0
          },
          "accumulatedPositioningError": {
            "itemsId": 0
          },
          "dwellTimeError": {
            "itemsId": 0
          },
          "repeatability": {
            "itemsId": 0
          },
          "doseEquivalentRate": {
            "itemsId": 0
          }
        }
      }
    },
    watch:{
      activeNameEquipment: {
        handler(val) {
          this.$nextTick(()=>{
            let resultId = this.basicForm.resultId;
            getInfoById(resultId).then(response => {
              if(response.code == 200){
                let data = response.data;
                for(let keys in data){
                  this.setData(keys,data[keys]);
                }
                 setTimeout(()=>{
                   this.initFlag = true;
                 },300)
              }
            }).catch((response) => {
               this.$emit("loadingchange", true);
             });
             });
        },
        deep: true,
        immediate: true
      },
      "form.sourceActivity":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'sourceActivity');
         }
        },
        deep:true,
      },
      "form.sourcePlaceAccuracy":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'sourcePlaceAccuracy');
         }
        },
        deep:true,
      },
      "form.accumulatedPositioningError":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'accumulatedPositioningError');
         }
        },
        deep:true,
      },
      "form.dwellTimeError":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'dwellTimeError');
         }
        },
        deep:true,
      },
      "form.repeatability":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'repeatability');
         }
        },
        deep:true,
      },
      "form.doseEquivalentRate":{
        handler(newName, oldName) {
         if(this.initFlag){
          this.validateData(newName,'doseEquivalentRate');
         }
        },
        deep:true,
      },
      "form.temperature":{
          handler(newName, oldName) {
            if(this.initFlag){
             this.validateData(this.form,'sdd');
            }
          },
        },
      "form.pressure":{
        handler(newName, oldName) {
          if(this.initFlag){
           this.validateData(this.form,'sdd');
          }
        },
      },
    },
    methods:{
      //修改数据
      setData(name,data){
        this.form[name] = data ? data : (this[name] ? {}:null);
      },
      //表单修改提交后端
       postForm(param,name){
         param['itemsId'] = this.form.itemsId;
         if(name == 'sourceActivity'){
           param['temperature'] = this.form.temperature;
           param['pressure'] = this.form.pressure;
         }
         this.$emit("loadingchange", true);
      	 postInfo(param,this[name].action).then(res=>{
      		 this.$emit("loadingchange", false);
      		 if(res.code == 200){
      			 this[name].flag = false;
      			 if(name != 'sdd'){
      				this.setData(name,res.data);
      			 }
      		 }
      	 })
      },
      validateType(arr,keys,obj){
      	if(obj.like){
      		for(let i=0;i<arr.length;i++){
      			if(keys.indexOf(arr[i]) != -1){
      				return true;
      			}
      		}
      		return false;
      	}else{
      		if(arr.indexOf(keys) != -1){
      			return true;
      		}
      		return false;
      	}
      },
       //数据验证
       validateData(newName,myName){
      	 if(!this[myName].noClear){
      		clearTimeout(this[myName].loading);
      	 }else{
      		 this[myName].noClear = false;
      	 }
         let regNumber = /^[-]?\d*([.](\d+))?$/;//小数验证正则
         let regRepNumber = /[^-?\d.,]/g;//将除小数外的符号消除正则
         let regInt = /^\d*$/;//整数验证正则
         let regRepInt = /[^-?\d,]/g;//将除小数外的符号消除正则
         let reg,regRep;
         let repStr = '';
      	 let intResult
         if(JSON.stringify(newName) != '{}'){
           //遍历该对象所有字段进行验证
           for(let keys in newName){
             //数字验证环节
      			 if((typeof newName[keys] == 'string') ||  (typeof newName[keys] == 'number')){
      				if(newName[keys] && !this.validateType(this[myName].notNumber,keys,this[myName])){
      					intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      					reg = intResult ? regInt:regNumber;
      				  let bool = !reg.test(newName[keys]);
      				  if(bool){
      						setTimeout(()=>{
      							intResult = this.validateType(this[myName].intNumber,keys,this[myName]);
      							regRep = intResult ? regRepInt:regRepNumber;
      									repStr = newName[keys] + '';
      							repStr =  repStr.replace(regRep,'');
      							if(repStr != (newName[keys]+'')){
      								if(!this[myName].noClear){
      									this[myName].noClear = true;
      								}
      								newName[keys] = repStr;
      							}
      						},100);
      						if(this[myName].flag){
      						 this[myName].flag = false;//如果数字验证不通过不需要请求后端
      						}
      				  }
      				}
      			 }
           }
      		 this.isPost(newName,myName);
         }
       },
       isPost(newName,myName){
      	 if(this[myName].flag){//是否请求后端判断
      	  let postBody = {};
      	  for(let i in newName){
      	    if(newName[i] !== null && newName[i] !== undefined){
      	      postBody[i] = newName[i];
      	    }
      	  }
      	  if(JSON.stringify(postBody) != '{}'){
      			this[myName].loading = setTimeout(()=>{
      				this.postForm(postBody,myName);
      			},800)
      	  }
      	 }else{
      		 this[myName].flag = true;
      	 }
       },
    },
  }
</script>

<style lang="scss" scoped>
  @import '../content.scss';

  .miniFont {
    font-size: 10px;
  }

  .miniFontCenter {
    margin-top: 8px;
  }

  .content53 {
    padding-inline: 0 !important;
    ::v-deep .el-input__suffix{
      display: none;
    }
    .latex{
      margin-top: 15px;
    }
    table {
      width: 100%;

      td {
        max-width: 100px;

        ::v-deep .el-checkbox__label {
          white-space: break-spaces;
        }
      }

      .el-input {
        width: 100% !important;
      }

      .multipleInput {
        .el-input {
          width: 50px !important;
        }
      }
    }

    .innertitle {
      display: block;
      margin-left: 0;
    }

    .table1 {
      .el-radio {
        display: flex;
        align-items: center;
      }
    }

    #hearderTR td:nth-child(7) {
      display: none;
    }
  }
</style>
